package org.example.ExperimentTwo;

import java.util.Scanner;

public class UserLogin {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = 0; // 记录尝试次数

        while (count < 3) {
            System.out.print("请输入用户名: ");
//            使用trim除字符串首尾空白字符
            String username = scanner.nextLine().trim();

            if (username.isEmpty()) {
                System.out.println("用户名不能为空，请重新输入！");
                continue;
            }

            System.out.print("请输入密码: ");
            String password = scanner.nextLine().trim();

            if (password.isEmpty()) {
                System.out.println("密码不能为空，请输入密码！");
                continue;
            }

            // 检查用户名和密码
            if ("mldn".equals(username) && "hello".equals(password)) {
                System.out.println("登录成功！");
                return; // 登录成功，退出循环
            } else {
                System.out.println("登录失败，用户名或密码错误！");
                count++;
            }

            if (count < 3) {
                System.out.println("您还有 " + (3 - count) + " 次尝试机会。");
            }
        }

        System.out.println("尝试次数过多，系统退出！");
    }
}